package com.charlie.meetingmanagement.controller;


import com.charlie.meetingmanagement.pojo.po.Meeting;
import com.charlie.meetingmanagement.pojo.po.PageBean;
import com.charlie.meetingmanagement.pojo.po.Result;
import com.charlie.meetingmanagement.service.MeetingService;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@CrossOrigin(origins = "*")
public class MeetingController {

    @Resource
    private MeetingService meetingService;

//    获取全部meeting数据
    @PostMapping("/meeting/meetingInfo")
    public Result meetingInfo(){
        log.info("查询会议室的全部数据");
        List<Meeting> meetingList = meetingService.meetingInfo();
        return Result.success(meetingList);
    }
    //前台获得全部会议室的消息
    @PostMapping("/meeting/getAllMeetingInfo")
    public Result getAllMeetingInfo(){
        List<Meeting> meetingList = meetingService.meetingInfo();
        return Result.success(meetingList);
    }

//    条件分页获取meeting数据
    @GetMapping("/meeting/meetingInfoMore")
    public Result meetingInfoMore(@RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer pageSize,
                                  @RequestParam(required = false) Integer meetingroomId,
                                  @RequestParam(required = false) Integer meetingroomSize,
                                  @RequestParam(required = false) String meetingroomHeadname)
    {
        log.info("分页查询meeting数据");
        PageBean pageBean = meetingService.page(page,pageSize,meetingroomId,meetingroomSize, meetingroomHeadname);
        return Result.success(pageBean);
    }

//    新增会议室
    @PostMapping("/meeting/insert")
    public Result insertMeeting(@RequestBody Meeting meeting){
        log.info("新增会议室");
        return meetingService.insertMeeting(meeting);
    }

//    根据会议室房间号删除会议室
    @GetMapping("/meeting/delete")
    public Result deleteMeeting(@RequestParam Integer meetingroomId){
        log.info("用户进行会议室删除，删除id：{}",meetingroomId);
        return meetingService.delete(meetingroomId);
    }

//    根据会议室ID,更新会议室内容
    @PostMapping("/meeting/update")
    public Result updateMeeting(@RequestBody Meeting meeting){
        log.info("正在进行会议室更新，更新id：{}",meeting.getMeetingroomId());
        return meetingService.updateMeeting(meeting);
    }
}
